package com.xx.account.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xx.common.annotation.Log;
import com.xx.common.core.controller.BaseController;
import com.xx.common.core.domain.AjaxResult;
import com.xx.common.enums.BusinessType;
import com.xx.account.domain.AccountWorker;
import com.xx.account.service.IAccountWorkerService;
import com.xx.common.utils.poi.ExcelUtil;
import com.xx.common.core.page.TableDataInfo;

/**
 * 投手Controller
 * 
 * @author ruoyi
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/account/worker")
public class AccountWorkerController extends BaseController
{
    @Autowired
    private IAccountWorkerService accountWorkerService;

    /**
     * 查询投手列表
     */
    @PreAuthorize("@ss.hasPermi('account:worker:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountWorker accountWorker)
    {
        startPage();
        List<AccountWorker> list = accountWorkerService.selectAccountWorkerList(accountWorker);
        return getDataTable(list);
    }

    /**
     * 导出投手列表
     */
    @PreAuthorize("@ss.hasPermi('account:worker:export')")
    @Log(title = "投手", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountWorker accountWorker)
    {
        List<AccountWorker> list = accountWorkerService.selectAccountWorkerList(accountWorker);
        ExcelUtil<AccountWorker> util = new ExcelUtil<AccountWorker>(AccountWorker.class);
        util.exportExcel(response, list, "投手数据");
    }

    /**
     * 获取投手详细信息
     */
    @PreAuthorize("@ss.hasPermi('account:worker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(accountWorkerService.selectAccountWorkerById(id));
    }

    /**
     * 新增投手
     */
    @PreAuthorize("@ss.hasPermi('account:worker:add')")
    @Log(title = "投手", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountWorker accountWorker)
    {
        return toAjax(accountWorkerService.insertAccountWorker(accountWorker));
    }

    /**
     * 修改投手
     */
    @PreAuthorize("@ss.hasPermi('account:worker:edit')")
    @Log(title = "投手", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountWorker accountWorker)
    {
        return toAjax(accountWorkerService.updateAccountWorker(accountWorker));
    }

    /**
     * 删除投手
     */
    @PreAuthorize("@ss.hasPermi('account:worker:remove')")
    @Log(title = "投手", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(accountWorkerService.deleteAccountWorkerByIds(ids));
    }
}
